package com.tools.common.container.r;

import com.tools.common.container.MapEnum;
import com.tools.common.container.RowKit;
import com.tools.common.container.SetEnum;
import com.tools.common.exception.InvalidOperationException;
import com.tools.common.object.Note;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.function.Predicate;

/**
 * 只读 HashSet 集合
 * */
@Note("只读 HashSet 集合")
public final class OnlyReadHashSet<T> extends HashSet<T> {

    public OnlyReadHashSet() {
        super();
    }

    @SafeVarargs
    public OnlyReadHashSet(T... elements) {
        super(SetEnum.calcInitSize(elements));
        if(elements == null) return;
        for(T obj : elements) super.add(obj);
    }

    public OnlyReadHashSet(Iterable<? extends T> elements) {
        super(MapEnum.calcInitSize(RowKit.getIterableSize(elements)));
        if(elements == null) return;
        for (T obj : elements) super.add(obj);
    }


    @Override
    public boolean add(T t) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean addAll(@NotNull Collection<? extends T> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean remove(Object o) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean removeIf(Predicate<? super T> filter) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }


    @Override
    public void clear() {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean retainAll(@NotNull Collection<?> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }
}
